package com.demo.user.service.impl;

import com.demo.user.converter.AuthUserConverter;
import com.demo.user.entity.AuthUser;
import com.demo.user.entity.table.AuthUserTableDef;
import com.demo.user.mapper.AuthUserMapper;
import com.demo.user.service.AuthUserService;
import com.demo.user.vo.AuthUserVO;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author DayDayUp
 * create on 2023-08-15
 **/
@Slf4j
@Service
public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, AuthUser> implements AuthUserService {

    @Resource
    private AuthUserMapper authUserMapper;
    @Resource
    private AuthUserConverter authUserConverter;


    @Override
    public AuthUserVO getUserByUsername(String username) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.where(AuthUserTableDef.AUTH_USER.USERNAME.eq(username));
        AuthUser authUser = authUserMapper.selectOneByQuery(queryWrapper);
        return authUserConverter.toAuthUserVO(authUser);
    }
}
